package panel;

import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import classe.*;

import java.util.ArrayList;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;

import org.jdesktop.swingx.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.data.category.*;

public class PageStat extends JXPanel {
	/**
	 * 
	 */
	/*
	private static final long serialVersionUID = 1L;
	private JXPanel stat,pageStatHaut,panelAffProf,panelAffClas;
	private JTabbedPane ongletsStat,ongletsAff;
	private DefaultCategoryDataset donneeVolProf,donneeVolEtud; 
	private JFreeChart graphVolProf,graphVolEtud;
	private ChartPanel chartPanelProf,chartPanelEtud;
	private JLabel labelPageStatHaut;
	private boolean []affichProf;
	private boolean []affichClas;
	private JCheckBox[] jCheckAffProf;
	private JCheckBox[] jCheckAffClas;
	
	public PageStat(){
		this.setLayout(new BorderLayout());  
		affichProf=new boolean [1];
		affichClas=new boolean [1];
		jCheckAffProf=new JCheckBox[1];
		jCheckAffClas=new JCheckBox[2];
		this.add(getPageGestUsrHaut(), BorderLayout.NORTH);
		this.add(getOngletsStat(), BorderLayout.CENTER);
		
		//miseAjour();
	}
	public JXPanel getPageGestUsrHaut(){
		if (pageStatHaut == null){
			pageStatHaut = new JXPanel();
		}
		pageStatHaut.setLayout(new FlowLayout());
		pageStatHaut.setPreferredSize(new Dimension(300,55));
		pageStatHaut.add(getLabelPageStatHaut());
		return pageStatHaut;
	}
	public JLabel getLabelPageStatHaut(){
		if (labelPageStatHaut==null){
			labelPageStatHaut = new JLabel("Statistique");
		}
		Font font = new Font("Verdana", Font.BOLD, 15);
		labelPageStatHaut.setFont(font);
		labelPageStatHaut.setHorizontalAlignment(SwingConstants.CENTER);
		return labelPageStatHaut;
	}
	public JXPanel getPanelStat(){ 
		if(stat==null){
			stat = new JXPanel();
		}
		stat.setLayout(new BorderLayout());  
		//stat.add(getPagecreActHaut(), BorderLayout.NORTH);
		stat.add(getOngletsStat(), BorderLayout.CENTER);
		
    	return stat;
	}
	public JTabbedPane getOngletsStat(){
		if(ongletsStat==null){
			ongletsStat = new JTabbedPane(SwingConstants.TOP);
		}  
		ongletsStat.addTab("Professeur", getChartPanelProf());  
		ongletsStat.addTab("Classe",getChartPanelEtud());
		ongletsStat.addTab("Option",getOngletsAff());
		ongletsStat.setOpaque(true);
		return ongletsStat;
	}
	public JTabbedPane getOngletsAff(){
		if(ongletsAff==null){
			ongletsAff = new JTabbedPane(SwingConstants.TOP);
		}  
		ongletsAff.addTab("Professeur", getPanelAffProf());  
		ongletsAff.addTab("Classe",getPanelAffClas());
		ongletsAff.setOpaque(true);
		return ongletsAff;
	}
	 public ChartPanel getChartPanelProf(){
	    	if(chartPanelProf==null){
	    		chartPanelProf= new ChartPanel(getGraphVolProf());
	    	}
	    	return chartPanelProf;
	    	
	  }
	 public JFreeChart getGraphVolProf(){
	    	if(graphVolProf==null){
	    		/*
	    		graphVolProf = ChartFactory.createStackedBarChart3D("Volume prestation Professeur",
	    				"Nom professeur", "Nombre d'heure", getDonneeVolProf(), PlotOrientation.VERTICAL,
	    				true,true, false);
	    		
	    		graphVolProf = ChartFactory.createBarChart3D("Volume prestation Professeur",
	    				"Nom professeur", "Nombre d'heure", getDonneeVolProf(), PlotOrientation.VERTICAL,
	    				true,true, false);
	    	}
	    	return graphVolProf;
	    			
	    }
		
		public DefaultCategoryDataset getDonneeVolProf(){
			if(donneeVolProf==null){
				donneeVolProf = new DefaultCategoryDataset();
			}
			/*
			for(int i =0;i<prof.size();i++){
				if(affichProf[i]){
					donneeVolProf.setValue(prof.get(i).getHmiss(),"Heure de mission" , prof.get(i).getNom());
					donneeVolProf.setValue(prof.get(i).getHcours(),"Heure de Cours" , prof.get(i).getNom());
					donneeVolProf.setValue(prof.get(i).getHTot(),"Heure Total" , prof.get(i).getNom());
				}
			}
			*/
			/*
			donneeVolProf.setValue(6, "Heure de mission", "Prof1");
			donneeVolProf.setValue(3, "Heure de Cours", "Prof1");
			donneeVolProf.setValue(7, "Heure de mission", "Prof2");
			donneeVolProf.setValue(10, "Heure de Cours", "Prof2");
			donneeVolProf.setValue(8, "Heure de mission", "Prof3");
			donneeVolProf.setValue(8, "Heure de Cours", "Prof3");
			donneeVolProf.setValue(5, "Heure de mission", "Prof4");
			donneeVolProf.setValue(6, "Heure de Cours", "Prof4");
			donneeVolProf.setValue(12, "Heure de mission", "Prof5");
			donneeVolProf.setValue(5, "Heure de Cours", "Prof5");
			
			return donneeVolProf;
		}
		public ChartPanel getChartPanelEtud(){
	    	if(chartPanelEtud==null){
	    		chartPanelEtud= new ChartPanel(getGraphVolEtud());
	    	}
	    	return chartPanelEtud;
	    	
	    }
	    public JFreeChart getGraphVolEtud(){
	    	if(graphVolEtud==null){
	    		graphVolEtud = ChartFactory.createStackedBarChart3D("Volume heure cours des classes",
	    				"Nom Classe", "Nombre d'heure",getDonneeVolEtud(), PlotOrientation.VERTICAL,
	    				true,true, false);
	    	}
	    	return graphVolEtud;
	    			
	    }
		
		public DefaultCategoryDataset getDonneeVolEtud(){
			if(donneeVolEtud==null){
				donneeVolEtud = new DefaultCategoryDataset();
			}
			/*
			for(int i =0;i<clas.size();i++){
				if(affichClas[i]){
					donneeVolEtud.setValue(clas.get(i).getHcours(),"Heure de Cours" , clas.get(i).getNom());
				}
			}
			
			return donneeVolEtud;
		}
	/*
		public void miseAjourProf(int i){
			donneeVolProf.setValue(prof.get(i).getHmiss(),"Heure de mission" , prof.get(i).getNom());
			donneeVolProf.setValue(prof.get(i).getHcours(),"Heure de Cours" , prof.get(i).getNom());
			donneeVolProf.setValue(prof.get(i).getHTot(),"Heure Total" , prof.get(i).getNom());
		}
		public void miseAjourProf(){
			for(int i=0;i<prof.size();i++){
				donneeVolProf.setValue(prof.get(i).getHTot(),"Heure Total" , prof.get(i).getNom());
				donneeVolProf.setValue(prof.get(i).getHmiss(),"Heure de mission" , prof.get(i).getNom());
				donneeVolProf.setValue(prof.get(i).getHcours(),"Heure de Cours" , prof.get(i).getNom());
				
			}
		}
		
		 public JXPanel getPanelAffProf(){
		    	if(panelAffProf==null){
		    		panelAffProf= new JXPanel();
		    	}
		    	panelAffProf.setLayout(new GridLayout(prof.size()/2,2,0,0));
			  	panelAffProf.setPreferredSize(new Dimension(500,600));			
			  	for(int i=0;i<jCheckAffProf.length;i++){
			  		jCheckAffProf[i] = new JCheckBox();
			  		jCheckAffProf[i].addItemListener(new ItemListener(){
						public void itemStateChanged(ItemEvent e){
							if(e.getStateChange() == ItemEvent.SELECTED){			
								changeAffProf(e.toString());				
							}
							else if (e.getStateChange() == ItemEvent.DESELECTED){
								changeAffProf(e.toString());	
							}
						}
					});
			  	}			  	
			  	for(int i=0;i<affichProf.length;i++){
			  		panelAffProf.add(jCheckAffProf[i]);
			  	}
		    	return panelAffProf;
		    	
		  }
		 public JXPanel getPanelAffClas(){
		    	if(panelAffClas==null){
		    		panelAffClas= new JXPanel();
		    	}
		    	panelAffClas.setLayout(new GridLayout(clas.size()/2,2,0,0));
		    	panelAffClas.setPreferredSize(new Dimension(500,600));			  	
			  	for(int i=0;i<jCheckAffClas.length;i++){
			  		jCheckAffClas[i] = new JCheckBox(clas.get(i).getNom(),affichClas[i]);
			  		jCheckAffClas[i].addItemListener(new ItemListener(){
						public void itemStateChanged(ItemEvent e){
							if(e.getStateChange() == ItemEvent.SELECTED){			
								changeAffClas(e.toString());				
							}
							else if (e.getStateChange() == ItemEvent.DESELECTED){
								changeAffClas(e.toString());	
							}
						}
					});
			  	}			  	
			  	for(int i=0;i<affichClas.length;i++){
			  		panelAffClas.add(jCheckAffClas[i]);
			  	}
		    	return panelAffClas;
		    	
		  }
		public void setAffich(boolean[] affich) {
			this.affichProf = affich;
		}
		public void changeAffProf(String txt) {
			int i=0;
			for( i=0;i<affichProf.length;i++){
				if(txt.indexOf(prof.get(i).getNom()) != -1)
				{
					break;
				}			
			}			
			if(affichProf[i]==true){
				affichProf[i]=false;
				donneeVolProf.clear();
				//donneeVolProf.removeRow(prof.get(i).getNom());
			}else{
				affichProf[i]=true;
			}
			for(int k=0;k<affichProf.length;k++){
				if(affichProf[k]){
					donneeVolProf.setValue(prof.get(k).getHmiss(),"Heure de mission" , prof.get(k).getNom());
					donneeVolProf.setValue(prof.get(k).getHcours(),"Heure de Cours" , prof.get(k).getNom());
					donneeVolProf.setValue(prof.get(k).getHTot(),"Heure Total" , prof.get(k).getNom());
				}
			}
				
		}
		public void changeAffClas(String txt) {
			int i=0;
			for( i=0;i<affichClas.length;i++){
				if(txt.indexOf(clas.get(i).getNom()) != -1)
				{
					break;
				}			
			}			
			if(affichClas[i]==true){
				affichClas[i]=false;
				donneeVolEtud.clear();
			}else{
				affichClas[i]=true;
			}
			for(int k=0;k<affichClas.length;k++){
				if(affichClas[k]){
					donneeVolEtud.setValue(clas.get(k).getHcours(), "Heure de Cours",clas.get(k).getNom());	
				}
			}
			
		}
		
		 */
}
